package com.zoe.app.config;

import cn.hutool.core.collection.CollUtil;
import com.zoe.app.context.OrderContext;
import com.zoe.app.filters.BaseFilter;
import com.zoe.app.filters.IBaseFilterChain;
import com.zoe.app.filters.LocalFilterChain;
import com.zoe.app.filters.filter.OneFilter;
import com.zoe.app.filters.filter.ThreeFilter;
import com.zoe.app.filters.filter.TwoFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author zbg
 * @date 2023/06/06
 * @description
 */
@Configuration
public class FilterChain {
    @Bean
    OneFilter oneFilter() {
        return new OneFilter();
    }

    @Bean
    TwoFilter twoFilter() {
        return new TwoFilter();
    }

    @Bean
    ThreeFilter threeFilter() {
        return new ThreeFilter();
    }

    @Bean
    IBaseFilterChain<OrderContext> orderChain() {
        List<BaseFilter<OrderContext>> filters = CollUtil.newArrayList(oneFilter(), twoFilter(), threeFilter());
        LocalFilterChain<OrderContext, BaseFilter<OrderContext>> orderContextBaseFilterLocalFilterChain = new LocalFilterChain<>(filters);
        return orderContextBaseFilterLocalFilterChain;
    }
}
